package com.learn.actionplatfo.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class InputCheckController {

    @RequestMapping("/inputCheck")
    public String inputCheck(String input){
        String msg="";
        String regex="\\\\?\\d*?\\.?(\\d?\\d?)+";
        String regexSec="\\\\?\\d*?\\.?(\\d?\\d?)";

        if(input==""){
            return "nullInput";
        }

        if (input.contains(".")){
            if(input.matches(regex)){
                char[] inputde = new char[1];
                input.getChars(0,1,inputde,0);
                char needed = inputde[0];
                if (needed == '.'){
                    msg = "NeededToBeAdd0";
                } else if(input.matches(regexSec)){
                    msg="OK";
                }else {
                    msg="DecimalDigitOverflow";
                }
            }else{
                msg="False";
            }
            return msg;
        }else{
            if(input.matches(regexSec)||input == null){
                msg="OK";
            }else{
                msg="False";
            }

            return msg;
        }
    }
}
